package com.yjt.admin.system.controller;


import com.yjt.admin.system.entity.RoleGroup;
import com.yjt.admin.system.form.PostForm;
import com.yjt.admin.system.form.RoleGroupForm;
import com.yjt.admin.system.service.RoleGroupService;
import com.yjt.common.enums.ModulEnum;
import com.yjt.common.enums.OperTypeEnum;
import com.yjt.common.log.annotation.OperLog;
import com.yjt.common.vo.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 角色组表 前端控制器
 * </p>
 *
 * @author zzp
 * @since 2021-10-12
 */
@RefreshScope // 支持Nacos的动态刷新功能
@RestController
@RequestMapping("/admin/system/role-group")
@Api(tags = "角色组管理")
public class RoleGroupController {

    @Autowired
    private RoleGroupService roleGroupService;

    @PostMapping("/add")
    @ApiOperation(value = "增加角色组信息", notes = "返回JSONObject")
    @OperLog(operModul = ModulEnum.ROLE_GROUP_MODUL, operType = OperTypeEnum.ADD, operDesc = "新增角色组信息")
    public CommonResult addRoleGroup(@RequestBody RoleGroupForm roleGroupForm) {
        RoleGroup roleGroup = new RoleGroup();
        BeanUtils.copyProperties(roleGroupForm,roleGroup);
        roleGroupService.save(roleGroup);
        return CommonResult.success("角色组新增成功");
    }


    @DeleteMapping("/delete")
    @ApiOperation(value = "删除角色组信息", notes = "返回JSONObject",hidden = true)
    @ApiImplicitParam(name = "roleGroupId", value = "角色组id")
    @OperLog(operModul = ModulEnum.ROLE_GROUP_MODUL, operType = OperTypeEnum.DEL, operDesc = "删除角色组信息")
    public CommonResult delRoleGroup(String roleGroupId) {
        roleGroupService.removeById(roleGroupId);
        return CommonResult.success("角色组删除成功");
    }

    @PutMapping("/update")
    @ApiOperation(value = "修改角色组信息", notes = "返回JSONObject")
    @OperLog(operModul = ModulEnum.ROLE_GROUP_MODUL, operType = OperTypeEnum.MOD, operDesc = "修改角色组信息")
    public CommonResult updateRoleGroup(@RequestBody RoleGroupForm roleGroupForm) {
        RoleGroup roleGroup = new RoleGroup();
        BeanUtils.copyProperties(roleGroupForm,roleGroup);
        roleGroupService.updateById(roleGroup);
        return CommonResult.success("角色组修改成功");
    }
}
